(function(){
    function main(){
        createElement();
        scrollTo();
        bindEvent();
    }
    function createElement(){
        var strVar = "";
        strVar += "<div class=\"totop\" style='display: none'>";
        strVar += "<div class=\"top-img\"><\/div>";
        strVar += "<div>回到<\/div>";
        strVar += "<div>顶部<\/div>";
        strVar += "<\/div>";
        $("body").append(strVar);
    }

    function scrollTo(){
        var winheight = $(window).height()/2;
        $(window).scroll(function(){
            var scrollheight = $(window).scrollTop();
            if(scrollheight > winheight){
                $(".totop").css("display","block");
            }else{
                $(".totop").css("display","none");
            }
        })
    }
    function bindEvent(){
        var $totop = $(".totop");
        $totop.on("click", function(){
            $("body,html").animate({scrollTop: '0px'}, 400);
        })
    }
    return main();
}())